package net.roobook.cms.modules.demo.controller;

import net.roobook.cms.common.redis.RedisService;
import net.roobook.cms.common.web.BaseController;
import net.roobook.cms.modules.demo.entity.DemoEntity;
import net.roobook.cms.modules.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Roobook
 * @email 327878610@qq.com
 * @link https://roobook.net
 * @Description Demo测试Controller
 * @date 2023/9/7 16:01
 **/
@Controller
@RequestMapping("demo")
public class DemoController extends BaseController {
    @Autowired
    private DemoService demoService;
    @Autowired
    private RedisService redisService;
    @ResponseBody
    @RequestMapping("/index")
    public String index(){
        return "index";
    }


    @ResponseBody
    @RequestMapping("/add")
    public int add(DemoEntity demo) {

        return demoService.add(demo);
    }


    @ResponseBody
    @RequestMapping("/del")
    public int delete(DemoEntity demo) {
        return demoService.delete(demo);
    }


    @ResponseBody
    @RequestMapping("/update")
    public int update(DemoEntity demo) {
        return demoService.update(demo);
    }

    @ResponseBody
    @RequestMapping("/list")
    public List<DemoEntity> queryDemoEntity(DemoEntity demo) {
        return demoService.queryDemoEntity(demo);
    }

    @ResponseBody
    @RequestMapping("/one")
    public DemoEntity queryDemoById(Integer id) {
        return demoService.queryDemoById(id);
    }

    @ResponseBody
    @RequestMapping("/redis")
    public String redis(Integer id) {
        redisService.setCacheObject("test","test");
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/getRedis")
    public String getRedis(Integer id) {
        return (String)redisService.getCacheObject("test");
    }



}
